<script>
$(document).ready(function() {
  $(".blockTable").tablesorter({
    textExtraction: function(node) {
      var attr = $(node).attr('data-sort-value');
      if (typeof attr !== 'undefined' && attr !== false) {
        return attr;
      }
      return $(node).text(); 
    } 
  });
});
</script>
<div class="table-responsive col-lg-12">
  <table class="table table-striped table-hover tablesorter blockTable">
    <thead>
      <tr>
        <th>{{ _("Age") }}</th>
        <th>{{ _("Shares") }}</th>
        <th>{{ _("Luck") }}</th>
        <th>{{ _("Round Duration") }}</th>
        <th>{{ _("Reward") }}</th>
        <th>{{ _("Difficulty") }}</th>
        <th>{{ _("Solved by") }}</th>
        <th>{{ _("Block Hash") }}</th>
        <th>{{ _("Blockheight") }}</th>
        <th>{{ _("Status") }}</th>
      </tr>
    </thead>
    <tbody>
    {% if current_block %}
    <tr class="active current_round" data-currency="{{ current_block['currency_data']['code'] }}">
      <td data-sort-value="100000000000">...</td>
      <td style="min-width: 85px;">
        <span class="shares_per_second_{{ current_block['currency_data']['code'] }}" style="display:none;">
          {% if current_block['shares_per_sec'] %}
          {{ '{:.16f}'.format(current_block['shares_per_sec']) }}
          {% endif %}
        </span>
        <span class="avg_shares_to_solve_{{ current_block['currency_data']['code'] }}" style="display:none;">
          {% if current_block['avg_shares_to_solve'] %}
          {{ '{:.16f}'.format(current_block['avg_shares_to_solve']) }}
          {% endif %}
        </span>
        <span class="blockshares_{{ current_block['currency_data']['code'] }}" style="display:none;">
          {% if current_block['shares'] %}
          {{ '{:.8f}'.format(current_block['shares']) }}
          {% endif %}
        </span>
        <span class="starttime_{{ current_block['currency_data']['code'] }}" style="display:none;">
          {{ current_block['start_time'] }}
        </span>
        <span class="blockshares">{{ current_block['shares'] | comma }}</span>
      </td>
      <td><span class="blockluck">???</span>%</td>
      <td><span class="hours">00</span>:<span class="minutes">00</span>:<span class="seconds">00</span></td>
      <td>{{ current_block['currency_data']['reward'] }}</td>
      <td>{{ current_block['currency_data']['difficulty'] | comma }}</td>
      <td>...</td>
      <td>...</td>
      <td>{{ current_block['currency_data']['height'] | comma }}</td>
      <td>
        {{ current_block['status'] }}
      </td>
    </tr>
    {% endif %}
    {% for block in blocks %}
    <tr>
      <td style="max-width:135px;" data-sort-value="{{ block.timestamp }}">{{ block.found_at | human_date_utc }}</td>
      <td>{{ '{:,}'.format(block.shares_to_solve | round(4) or 1).rstrip('0').rstrip('.') }}</td>
      <td>{{ '{:,}'.format((block.luck or 0) | round(2)) }} %</td>
      <td data-sort-value="{{ block.duration.total_seconds() }}">{{ block.duration }}</td>
      <td>{{ '{:,.8f}'.format(block.total_value) }}</td>
      <td>{{ '{:,}'.format(block.difficulty | round(4)) }}</td>
      <td>{% if block.user in g.anon_users %}
            Anonymous
          {% else %}
            <a href="/stats/{{ block.user }}">{{ block.user | truncate(9, True) }}</a>
          {% endif %}
      </td>
      <td><a href="/block/{{ block.hash }}">{{ block.hash | truncate(9, True) }}</a></td>
      <td>{{ '{:,}'.format(block.height) }}</td>
      <td>{{ block.status }}</td>
    </tr>
    {% else %}
    <tr>
      <th colspan="10">{{ _("No blocks matching that criteria") }}</th>
    </tr>
    {% endfor %}
    </tbody>
  </table>
</div>
